我的助手介面是用customtkinter做的,所以今天來簡單介紹一下
customtkinter.CTkLabel
customtkinter.CTkEntry
customtkinter.CTkButton
customtkinter.CTkTextbox
(這在舊版 Tkinter 中是 Text
)customtkinter.CTkCheckBox
在 Tkinter 和 CustomTkinter 中,常用的字體樣式有:
"bold"
:粗體"italic"
:斜體"underline"
:底線"overstrike"
:刪除線設定主題外觀,這裡我們使用淺色模式
同時設定粗體和斜體,字型為 Arial,大小為 20,可以這樣寫:
設定顏色
範例
import customtkinter
def button_click():
input_text = entry.get()
print(f"輸入框的內容:{input_text}")
# 設定主題外觀
customtkinter.set_appearance_mode("light")
# 建立主視窗
app = customtkinter.CTk()
app.title("客製化元件範例")
app.geometry("500x300")
# 1. 客製化文字標籤 (Label)
# 改變文字顏色、大小和字體
title_label = customtkinter.CTkLabel(
app,
text="CustomTkinter 客製化",
text_color="#ff5733", # 使用十六進位顏色碼,橙紅色
font=("timesnewroman", 28, "italic") # 字體, 大小, 樣式
)
title_label.pack(pady=20)
# 2. 客製化輸入框 (Entry)
# 改變背景顏色和圓角
entry = customtkinter.CTkEntry(
app,
placeholder_text="在這裡輸入",
fg_color="#e0e0e0", # 淺灰色
corner_radius=10,
width=300
)
entry.pack(pady=10)
# 3. 客製化按鈕 (Button)
# 改變背景顏色、滑鼠停留顏色和文字顏色
button = customtkinter.CTkButton(
app,
text="提交",
command=button_click,
fg_color="#4CAF50", # 綠色
hover_color="#c8d628", # 滑鼠停留時的顏色
text_color="#ffffff", # 白色
corner_radius=15,
width=200
)
button.pack(pady=20)
app.mainloop()